package com.fyzk.activity.zoushitu;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tyjc.lottery.R;


public class ZST_sheZhi extends Activity{
	
	private TextView cancel,sure;
	
	private LinearLayout ll_qishu_30,ll_qishu_50,ll_qishu_100,ll_zhexian1,ll_zhexian2,ll_yilou1,ll_yilou2,ll_tongji1,ll_tongji2;
	private ImageView iv_qishu_30,iv_qishu_50,iv_qishu_100,iv_zhexian1,iv_zhexian2,iv_yilou1,iv_yilou2,iv_tongji1,iv_tongji2;
	
	private boolean qs_30,qs_50,qs_100=true,zx1=true,yl1=true,tj1=true;
	
	private int qiShu = 30;
	
	public static final String ZST_QISHU = "qishu";
	public static final String ZST_ZHEXIAN = "zhexian";
	public static final String ZST_YILOU = "yilou";
	public static final String ZST_TONGJI = "tongji";
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.zoushitu_shezhi);
		//设置不可点击边框以外区域
		this.setFinishOnTouchOutside(false);
		
		info();
		
		qiShu = getIntent().getIntExtra(ZST_sheZhi.ZST_QISHU, 100);
		zx1 = getIntent().getBooleanExtra(ZST_sheZhi.ZST_ZHEXIAN, true);
		yl1 = getIntent().getBooleanExtra(ZST_sheZhi.ZST_YILOU, true);
		tj1 = getIntent().getBooleanExtra(ZST_sheZhi.ZST_TONGJI, true);
		
		switch (qiShu) {
		case 30:
			qs_30 = true;
			qs_50 = false;
			qs_100 = false;
			break;
		case 50:
			qs_30 = false;
			qs_50 = true;
			qs_100 = false;
			break;
		case 100:
			qs_30 = false;
			qs_50 = false;
			qs_100 = true;
			break;

		default:
			break;
		}
	}
	
	@Override
	protected void onStart() {
		super.onStart();
		
		qiShu_check();
		zheXian_check();
		yiLou_check();
		tongJi_check();
	}
	
	/**
	 * 控件初始化
	 */
	private void info(){
		cancel = (TextView)findViewById(R.id.zst_sz_btm_cancel);
		sure = (TextView)findViewById(R.id.zst_sz_btm_sure);
		
		ll_qishu_30 = (LinearLayout)findViewById(R.id.zst_sz_qishu_30ll);
		ll_qishu_50 = (LinearLayout)findViewById(R.id.zst_sz_qishu_50ll);
		ll_qishu_100 = (LinearLayout)findViewById(R.id.zst_sz_qishu_100ll);
		ll_zhexian1 = (LinearLayout)findViewById(R.id.zst_sz_zhexian1);
		ll_zhexian2 = (LinearLayout)findViewById(R.id.zst_sz_zhexian2);
		ll_yilou1 = (LinearLayout)findViewById(R.id.zst_sz_yilou1);
		ll_yilou2 = (LinearLayout)findViewById(R.id.zst_sz_yilou2);
		ll_tongji1 = (LinearLayout)findViewById(R.id.zst_sz_tongji1);
		ll_tongji2 = (LinearLayout)findViewById(R.id.zst_sz_tongji2);
		
		iv_qishu_30 = (ImageView)findViewById(R.id.zst_sz_qishu_30iv);
		iv_qishu_50 = (ImageView)findViewById(R.id.zst_sz_qishu_50iv);
		iv_qishu_100 = (ImageView)findViewById(R.id.zst_sz_qishu_100iv);
		iv_zhexian1 = (ImageView)findViewById(R.id.zst_sz_zhexian1_iv);
		iv_zhexian2 = (ImageView)findViewById(R.id.zst_sz_zhexian2_iv);
		iv_yilou1 = (ImageView)findViewById(R.id.zst_sz_yilou1_iv);
		iv_yilou2 = (ImageView)findViewById(R.id.zst_sz_yilou2_iv);
		iv_tongji1 = (ImageView)findViewById(R.id.zst_sz_tongji1_iv);
		iv_tongji2 = (ImageView)findViewById(R.id.zst_sz_tongji2_iv);
		
		//方法
		cancel.setOnClickListener(new ZST_SZ_onClick());
		sure.setOnClickListener(new ZST_SZ_onClick());
		
		ll_qishu_30.setOnClickListener(new ZST_SZ_onClick());
		ll_qishu_50.setOnClickListener(new ZST_SZ_onClick());
		ll_qishu_100.setOnClickListener(new ZST_SZ_onClick());
		ll_zhexian1.setOnClickListener(new ZST_SZ_onClick());
		ll_zhexian2.setOnClickListener(new ZST_SZ_onClick());
		ll_yilou1.setOnClickListener(new ZST_SZ_onClick());
		ll_yilou2.setOnClickListener(new ZST_SZ_onClick());
		ll_tongji1.setOnClickListener(new ZST_SZ_onClick());
		ll_tongji2.setOnClickListener(new ZST_SZ_onClick());
		
	}
	
	/**
	 * 期数复选框
	 */
	private void qiShu_check(){
		if(qs_30){
			iv_qishu_30.setImageResource(R.drawable.zst_radio_checked);
			iv_qishu_50.setImageResource(R.drawable.zst_radio_normal);
			iv_qishu_100.setImageResource(R.drawable.zst_radio_normal);
			
			qiShu = 30;
		}else if(qs_50){
			iv_qishu_30.setImageResource(R.drawable.zst_radio_normal);
			iv_qishu_50.setImageResource(R.drawable.zst_radio_checked);
			iv_qishu_100.setImageResource(R.drawable.zst_radio_normal);
			
			qiShu = 50;
		}else{
			iv_qishu_30.setImageResource(R.drawable.zst_radio_normal);
			iv_qishu_50.setImageResource(R.drawable.zst_radio_normal);
			iv_qishu_100.setImageResource(R.drawable.zst_radio_checked);
			
			qiShu = 100;
		}
	}
	
	/**
	 * 折线复选框
	 */
	private void zheXian_check(){
		if(zx1){
			iv_zhexian1.setImageResource(R.drawable.zst_radio_checked);
			iv_zhexian2.setImageResource(R.drawable.zst_radio_normal);
		}else{
			iv_zhexian1.setImageResource(R.drawable.zst_radio_normal);
			iv_zhexian2.setImageResource(R.drawable.zst_radio_checked);
		}
	}
	
	/**
	 * 遗漏复选框
	 */
	private void yiLou_check(){
		if(yl1){
			iv_yilou1.setImageResource(R.drawable.zst_radio_checked);
			iv_yilou2.setImageResource(R.drawable.zst_radio_normal);
		}else{
			iv_yilou1.setImageResource(R.drawable.zst_radio_normal);
			iv_yilou2.setImageResource(R.drawable.zst_radio_checked);
		}
	}
	
	/**
	 * 统计复选框
	 */
	private void tongJi_check(){
		if(tj1){
			iv_tongji1.setImageResource(R.drawable.zst_radio_checked);
			iv_tongji2.setImageResource(R.drawable.zst_radio_normal);
		}else{
			iv_tongji1.setImageResource(R.drawable.zst_radio_normal);
			iv_tongji2.setImageResource(R.drawable.zst_radio_checked);
		}
	}

	/**
	 * 单击事件
	 * @author Administrator
	 *
	 */
	class ZST_SZ_onClick implements OnClickListener{
		
		Intent intent = null;

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.zst_sz_btm_cancel:
				ZST_sheZhi.this.finish();
				break;
			case R.id.zst_sz_btm_sure:
				
				intent = new Intent();
				intent.putExtra(ZST_QISHU, qiShu);
				intent.putExtra(ZST_ZHEXIAN, zx1);
				intent.putExtra(ZST_YILOU, yl1);
				intent.putExtra(ZST_TONGJI, tj1);
				setResult(0, intent);
				ZST_sheZhi.this.finish();
				
				break;
			case R.id.zst_sz_qishu_30ll:
				qs_30 = true;
				qs_50 = false;
				qs_100 = false;
				
				qiShu_check();
				break;
			case R.id.zst_sz_qishu_50ll:
				qs_30 = false;
				qs_50 = true;
				qs_100 = false;
				
				qiShu_check();
				break;
			case R.id.zst_sz_qishu_100ll:
				qs_30 = false;
				qs_50 = false;
				qs_100 = true;
				
				qiShu_check();
				break;
			case R.id.zst_sz_zhexian1:
				zx1 = true;
				zheXian_check();
				break;
			case R.id.zst_sz_zhexian2:
				zx1 = false;
				zheXian_check();
				break;
			case R.id.zst_sz_yilou1:
				yl1 = true;
				yiLou_check();
				break;
			case R.id.zst_sz_yilou2:
				yl1 = false;
				yiLou_check();
				break;
			case R.id.zst_sz_tongji1:
				tj1 = true;
				tongJi_check();
				break;
			case R.id.zst_sz_tongji2:
				tj1 = false;
				tongJi_check();
				break;
			default:
				break;
			}
			
		}
		
	}
}
